package com.shangxia.lucky.common.util.file;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;

/**
 * @ProjectName: monomer
 * @ClassName: ReadTXTUtil
 * @Time: 2021/8/9
 * @Author: zhouy
 * @Description:
 * @Experience:
 */

@Slf4j
public class ReadTXTUtil {
    public static List<List<Integer>> readRealCode(String filePath, String fileName) throws IOException {
        List<List<Integer>> readTxtList = new ArrayList<>();
        BufferedReader br = new BufferedReader(new FileReader(new File(filePath + fileName)));
        String str;
        int count = 0;
        while ((str = br.readLine()) != null) {
            str.trim();
            List<Integer> list = new ArrayList();
            Arrays.stream(str.split(" ")).forEach(e -> list.add(Integer.parseInt(e)));
            readTxtList.add(count++, list);
        }
        br.close();
        return readTxtList;
    }

    public static void readRealCodeSet(String filePath, String fileName, Set<Set<Integer>> readTxtList) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(new File(filePath + fileName)));
        String str;
        while ((str = br.readLine()) != null) {
            str.trim();
            Set<Integer> list = new HashSet<>();
            Arrays.stream(str.split(" ")).forEach(e -> list.add(Integer.parseInt(e)));
            readTxtList.add(list);
        }
        br.close();
    }

    /**
     * = 号 map
     * @param filePath
     * @param fileName
     * @return
     * @throws IOException
     */
    public static List<List<Integer>> readMatchCulomnCode(String filePath, String fileName) throws IOException {
        List<List<Integer>> readTxtList = new ArrayList<>();
        BufferedReader br = new BufferedReader(new FileReader(new File(filePath + fileName)));
        String str;
        int count = 0;
        while ((str = br.readLine()) != null) {
            str.trim();
            List<Integer> list = new ArrayList();
            String[] split = str.split("=");
            list.add(Integer.parseInt(split[0].trim()));
            Arrays.stream(split[1].trim().split(" ")).forEach(e -> list.add(Integer.parseInt(e)));
            readTxtList.add(count++, list);
        }
        br.close();
        return readTxtList;
    }

}
